<?php
/**
 * Description of EncodingHelper
 * provide different encoding convert methods
 * @todo this is not a helper, the function should be moved in AramisToolkip
 * @author ben
 */
class EncodingHelper
{
    /**
     * convert input to utf8 encoding
     *
     * @param mixed $in
     * @return false|mixed the result encoded
     */
    public static function toUtf8($in)
    {
        $out = false;

        if (is_array($in))
        {
            foreach ($in as $key => $value)
            {
                $out[self::toUtf8($key)] = self::toUtf8($value);
            }
        } 
        elseif(is_string($in))
        {
            return utf8_encode($in);
//            return mb_convert_encoding ( $in , "UTF-8" );

//            if(mb_detect_encoding($in) != "UTF-8")
//                return utf8_encode($in);
//            else
//                return $in;
        } 
        else
        {
            return $in;
        }
        return $out;
    }

    /**
     * utf8 decoding
     *
     * @param mixed $in
     * @return false|mixed the result encoded
     */
    public static function decodeUtf8($in)
    {
        $out = false;

        if (is_array($in))
        {
            foreach ($in as $key => $value)
            {
                $out[self::decodeUtf8($key)] = self::decodeUtf8($value);
            }
        }
        elseif(is_string($in))
        {
            return utf8_decode($in);
        }
        else
        {
            return $in;
        }
        return $out;
    }
}
